@include('admin.layout.bone_header')

<div class="layui-btn-container">

    <button class="layui-btn" data-type="addImages">添加分类</button>

</div>


<table class="layui-hide" id="think-table" lay-filter="think-table"></table>

<script type="text/html" id="barDemo">

    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">编辑</a>


</script>

<script>

    layui.use('table', function () {
        let table = layui.table;
        UI.getPageTable(table, "{{route('admin.categorys.categorys')}}", [
            {field: 'category_id', title: 'ID', width: 80, sort: true, fixed: 'left'}
            , {field: 'title', title: ' 分类名称'}
            , {field: 'show', title: ' 显示状态',templet:function (d){
                let arr = ['隐藏','显示'];
                return arr[d['show']];
                }}
            ,{fixed: 'right',title:'操作', align:'center', toolbar: '#barDemo'}
        ]);

        table.on('tool(think-table)', function (obj) {
            let data = obj.data;
            if(obj.event === 'edit'){
                UI.openLayer("{{route('admin.categorys.edit')}}?category_id="+data['category_id'],600,300);
            }else if(obj.event == 'del'){
                UI.delete(data['category_id'],function(res){
                    table.reload('think-table');
                },"{{route('admin.categorys.del')}}");
            }
        });
        let $ = layui.$, active = {
            addImages:function (){
                UI.openLayer("{{route('admin.categorys.add')}}",600,300);
            }
        };
        $('.layui-btn-container .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.search .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    })


</script>


@include('admin.layout.bone_footer')
